package com.tarena.lbs.user.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.user.pojo.param.UserGroupParam;
import com.tarena.lbs.user.pojo.query.UserGroupQuery;
import com.tarena.lbs.user.pojo.vo.UserGroupVO;
import com.tarena.lbs.user.service.UserGroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用户人群业务相关
 */
@Api(tags = "用户人群管理")
@RestController
@Slf4j
public class UserGroupController {

    @Autowired
    UserGroupService userGroupService;
    @ApiOperation("人群数据分页列表")
    @PostMapping("/admin/basic/userGroup/list")//人群列表
    public Result<PageResult<UserGroupVO>> pageList(UserGroupQuery userGroupParam) throws BusinessException {
        log.debug("用户列表控制层");
        PageResult<UserGroupVO> pageResult = userGroupService.pageList(userGroupParam);
        return new Result("0","success",pageResult);
    }

    @ApiOperation("保存人群数据")
    @PostMapping("/admin/basic/userGroup/save")//新增用户分组
    public Result<Void> save(@RequestBody UserGroupParam param,@RequestHeader("Authorization") String token)throws BusinessException
    {
        log.debug("新增用户分组参数控制层：{}",param);
        userGroupService.save(param,token);
        return Result.success();
    }
}
